package com.xiongwei.manageback.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xiongwei.manageback.DTO.BlogDTO;
import com.xiongwei.manageback.domain.SysBlog;
import com.xiongwei.manageback.service.SysBlogService;
import com.xiongwei.manageback.mapper.SysBlogMapper;
import com.xiongwei.manageback.utils.AjaxResult;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
* @author a
* @description 针对表【sys_blog(文章表)】的数据库操作Service实现
* @createDate 2023-11-08 09:02:02
*/
@Service
public class SysBlogServiceImpl extends ServiceImpl<SysBlogMapper, SysBlog>
    implements SysBlogService{

    @Override
    public List<BlogDTO> getByUserId(Integer userId) {
        LambdaQueryWrapper<SysBlog> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(SysBlog::getUserId,userId);
        List<SysBlog> blogs = list(wrapper);
        ArrayList<BlogDTO> blogDTOS = new ArrayList<>();
        for (SysBlog blog : blogs) {
            BlogDTO blogDTO = BeanUtil.copyProperties(blog, BlogDTO.class);
            blogDTO.setDesc(blog.getContent().substring(0,30));

            blogDTOS.add(blogDTO);
        }
        return blogDTOS;
    }
}




